#include "netcal.hpp"
#include "Protocol.hpp"
#include "TCPserver.hpp"
#include <memory>

void usage(std::string proc)
{
    std::cout << "you should use like this:" << proc << " port" << std::endl;
}
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        usage(argv[0]);
        exit(1);
    }
    std::unique_ptr<Cal> cal = std::make_unique<Cal>();
    std::unique_ptr<Protocol> protocolptr = std::make_unique<Protocol>([&cal](Request &req) -> Response
                                                                       { return cal->Excute(req); });

    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(std::stoi(argv[1]), [&protocolptr](std::shared_ptr<Socket> &sock, inetaddr &client)
                                                                  { protocolptr->GetRequest(sock, client); });
    tsvr->start();
}